#ifndef BSP_GPIO_H
#define BSP_GPIO_H

#include "gd32f30x.h"
#include "systick.h"

/* AB 绕组 */
#define PORT_WINDING_AP GPIOC       
#define PIN_WINDING_AP  GPIO_PIN_6  /* A+绕组 */
#define PORT_WINDING_AN GPIOC       /* A-绕组 */
#define PIN_WINDING_AN  GPIO_PIN_7  /* A-绕组 */
#define PORT_WINDING_BP GPIOC       /* B+绕组 */
#define PIN_WINDING_BP  GPIO_PIN_8  /* B+绕组 */
#define PORT_WINDING_BN GPIOC       /* B-绕组 */
#define PIN_WINDING_BN  GPIO_PIN_9  /* B-绕组 */

/* 485 DIR */
#define PORT_RS485_DIR GPIOB   
#define PIN_RS485_DIR  GPIO_PIN_8

/* LED */
#define PORT_SYSTEM_LED GPIOB   
#define PIN_SYSTEM_LED  GPIO_PIN_9

/* ERR */
#define PORT_OUT_ERR GPIOB   
#define PIN_OUT_ERR  GPIO_PIN_10

/* START 信号(使能信号) */
//#define PORT_START_MOTOR GPIOA   
//#define PIN_START_MOTOR  GPIO_PIN_8

/* SW1~8 */
#define PORT_SW1 GPIOB   
#define PIN_SW1  GPIO_PIN_0
#define PORT_SW2 GPIOB   
#define PIN_SW2  GPIO_PIN_1
#define PORT_SW3 GPIOB   
#define PIN_SW3  GPIO_PIN_2
#define PORT_SW4 GPIOB   
#define PIN_SW4  GPIO_PIN_3
#define PORT_SW5 GPIOB   
#define PIN_SW5  GPIO_PIN_4
#define PORT_SW6 GPIOB   
#define PIN_SW6  GPIO_PIN_5
#define PORT_SW7 GPIOB   
#define PIN_SW7  GPIO_PIN_6
#define PORT_SW8 GPIOB   
#define PIN_SW8  GPIO_PIN_7

/* 绕组AB设置 接口 */
#define BSP_GPIO_WINDING_AP_SET(x) gpio_bit_write(PORT_WINDING_AP, PIN_WINDING_AP, (bit_status)(x))
#define BSP_GPIO_WINDING_AN_SET(x) gpio_bit_write(PORT_WINDING_AN, PIN_WINDING_AN, (bit_status)(x))
#define BSP_GPIO_WINDING_BP_SET(x) gpio_bit_write(PORT_WINDING_BP, PIN_WINDING_BP, (bit_status)(x))
#define BSP_GPIO_WINDING_BN_SET(x) gpio_bit_write(PORT_WINDING_BN, PIN_WINDING_BN, (bit_status)(x))
/* RS485 DIR 接口 */
#define BSP_GPIO_RS485_DIR_SET(x) gpio_bit_write(PORT_RS485_DIR, PIN_RS485_DIR, (bit_status)(x))
/* LED 接口 */
#define BSP_GPIO_SYSTEM_LED_SET(x) gpio_bit_write(PORT_SYSTEM_LED, PIN_SYSTEM_LED, (bit_status)(x))
/* ERR 接口 */
#define BSP_GPIO_ERR_SET(x) gpio_bit_write(PORT_OUT_ERR, PIN_OUT_ERR, (bit_status)(x))
/* START 接口 */
#define BSP_GPIO_START_MOTOR_SET(x) gpio_bit_write(PORT_START_MOTOR, PIN_START_MOTOR, (bit_status)(x))

/* SW1~8 接口 */
#define BSP_GPIO_SW1_GET() gpio_input_bit_get(PORT_SW1, PIN_SW1)
#define BSP_GPIO_SW2_GET() gpio_input_bit_get(PORT_SW2, PIN_SW2)
#define BSP_GPIO_SW3_GET() gpio_input_bit_get(PORT_SW3, PIN_SW3)
#define BSP_GPIO_SW4_GET() gpio_input_bit_get(PORT_SW4, PIN_SW4)
#define BSP_GPIO_SW5_GET() gpio_input_bit_get(PORT_SW5, PIN_SW5)
#define BSP_GPIO_SW6_GET() gpio_input_bit_get(PORT_SW6, PIN_SW6)
#define BSP_GPIO_SW7_GET() gpio_input_bit_get(PORT_SW7, PIN_SW7)
#define BSP_GPIO_SW8_GET() gpio_input_bit_get(PORT_SW8, PIN_SW8)

extern void bsp_gpio_init(void);

#endif 
